package com.ruoyi.web.controller.warehouseManagement;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InventoryTransactionDetails;
import com.ruoyi.system.service.IInventoryTransactionDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出入库明细 Controller
 *
 * @author ruoyi
 * @date 2025-05-30
 */
@Api(tags="出入库明细")
@RestController
@RequestMapping("/system/inventoryTransactionDetails")
public class InventoryTransactionDetailsController extends BaseController
{
    @Autowired
    private IInventoryTransactionDetailsService inventoryTransactionDetailsService;

    /**
     * 通过仓库名称,出入库类型和出入库单号，开始时间，结束时间和商品名称查询出入库明细列表
     */
    @ApiOperation("通过仓库名称,出入库类型和出入库单号，开始时间，结束时间和商品名称查询出入库明细列表")
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String warehouseName, @RequestParam (required = false) String transactionType, @RequestParam (required = false) String transactionNumber, @RequestParam (required = false) Date startTime, @RequestParam (required = false) Date endTime,
                              @RequestParam (required = false) String productName)
    {
        startPage();
        List<InventoryTransactionDetails> list = inventoryTransactionDetailsService.selectInventoryTransactionDetailsListByConditions(warehouseName,transactionType,transactionNumber,startTime,endTime,productName);
        return getDataTable(list);
    }

    /**
     * 导出出入库明细列表
     */
    @ApiOperation("导出出入库明细列表")
    @PreAuthorize("@ss.hasPermi('system:details:export')")
    @Log(title = "出入库明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String warehouseName,@RequestParam (required = false) String transactionType,@RequestParam (required = false) String transactionNumber,@RequestParam (required = false) Date startTime,@RequestParam (required = false) Date endTime,
                       @RequestParam (required = false) String productName)
    {
        List<InventoryTransactionDetails> list = inventoryTransactionDetailsService.selectInventoryTransactionDetailsListByConditions(warehouseName,transactionType,transactionNumber,startTime,endTime,productName);
        ExcelUtil<InventoryTransactionDetails> util = new ExcelUtil<InventoryTransactionDetails>(InventoryTransactionDetails.class);
        util.exportExcel(response, list, "出入库明细数据");
    }

    /**
     * 通过id获取出入库明细详细信息
     */
    @ApiOperation("通过id获取出入库明细详细信息")
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryTransactionDetailsService.selectInventoryTransactionDetailsById(id));
    }

    /**
     * 新增出入库明细
     */
    @ApiOperation("新增出入库明细")
    @PreAuthorize("@ss.hasPermi('system:details:add')")
    @Log(title = "出入库明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryTransactionDetails inventoryTransactionDetails)
    {
        return toAjax(inventoryTransactionDetailsService.insertInventoryTransactionDetails(inventoryTransactionDetails));
    }

    /**
     * 修改出入库明细
     */
    @ApiOperation("修改出入库明细")
    @PreAuthorize("@ss.hasPermi('system:details:edit')")
    @Log(title = "出入库明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryTransactionDetails inventoryTransactionDetails)
    {
        return toAjax(inventoryTransactionDetailsService.updateInventoryTransactionDetails(inventoryTransactionDetails));
    }

    /**
     * 通过id批量删除出入库明细信息
     */
    @ApiOperation("通过id批量删除出入库明细信息")
    @PreAuthorize("@ss.hasPermi('system:details:remove')")
    @Log(title = "出入库明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryTransactionDetailsService.deleteInventoryTransactionDetailsByIds(ids));
    }
}
